<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AdminIdentity
 *
 * @author thanhdx
 */
class AdminIdentity extends CUserIdentity {
    const ERROR_ROLE_ADMIN_INVALID = 3; // invalid role admin

    public function authenticate() {
        $user = AdminUsers::model()->findByPk(array('username'=>$this->username));
        if($user === null){
            $this->errorCode = self::ERROR_USERNAME_INVALID;
        }  elseif($user->getAttribute('password') != md5($this->password)) {
            $this->errorCode = self::ERROR_PASSWORD_INVALID;
        }  elseif ($user->getAttribute("role_id") != 1) {
            $this->errorCode = self::ERROR_ROLE_ADMIN_INVALID;
        }else{
            $this->errorCode = self::ERROR_NONE;
        }
        return !$this->errorCode;
    }

}

?>
